﻿using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Bit.Art.Sso.Db
{
    /// <summary>
    /// 
    /// </summary>
    // 参考文档：https://codingblast.com/entityframework-core-add-implementation-idesigntimedbcontextfactory-multiple-dbcontexts/
    //
    // 数据库创建步骤：
    // 1. 只运行一次：
    //      dotnet ef migrations add v1 -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
    //      dotnet ef migrations add v1 -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
    //      dotnet ef migrations add v1 -c ApplicationUserDbContext -o Data/Migrations/IdentityServer/ApplicationUserDb
    //
    // 3. 创建数据库
    //      dotnet ef database update -c PersistedGrantDbContext
    //      dotnet ef database update -c ConfigurationDbContext
    //      dotnet ef database update -c ApplicationUserDbContext
    // 4. 升级数据库结构 - 将用户表的主键从GUID改成int
    //      dotnet ef migrations add IdentityPkToInt -c ApplicationUserDbContext -o Data/Migrations/IdentityServer/ApplicationUserDb
    public class ApplicationUserDbContext : IdentityDbContext<ApplicationUser, IdentityRole<ulong>, ulong>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="options"></param>
        public ApplicationUserDbContext(DbContextOptions<ApplicationUserDbContext> options)
            : base(options)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        }
    }
}
